let template = '我是{{name}}，年龄{{age}}，性别{{sex}}';
let data = {
  name: '姓名',
  age: 18,
};
console.log(render(template, data)); // 我是姓名，年龄18，性别undefined

function render(template, data) {
  const reg = /\{\{(\w+)\}\}/g;
  const keys = template.matchAll(reg);
  console.log(Array.from(keys));
  for (let key of keys) {
    template = template.replaceAll(key[0], data[key[1]]);
  }
  return template;
}
